/*
 * Copyright (C) 2019 GreenWaves Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* 
 * Authors: Eric Flamand, GreenWaves Technologies (eric.flamand@greenwaves-technologies.com)
 *          Germain Haugou, GreenWaves Technologies (germain.haugou@greenwaves-technologies.com)
 */

// TODO should be moved to pmsis
#define FIX2FP(Val, Precision)                      ((float) (Val) / (float) (1<<(Precision)))
#define FP2FIXR(Val, Precision)                     ((int)((Val)*((1 << (Precision))-1) + 0.5))
#define FP2FIX(Val, Precision)                      ((int)((Val)*((1 << (Precision))-1)))
#include "jpeg_constants.h"
#include "pmsis.h"

#define F0 1.0f
#define F1 1.387039845f
#define F2 1.306562965f
#define F3 1.175875602f
#define F4 1.0f
#define F5 0.785694958f
#define F6 0.541196100f
#define F7 0.275899379f

PI_L2 JPG_CST JpegConstants = {
	// const short int FDCT_FACTORS[] =
	{
	FP2FIX(1.0f/(F0*F0*8), Q11), FP2FIX(1.0f/(F0*F1*8), Q11), FP2FIX(1.0f/(F0*F2*8), Q11), FP2FIX(1.0f/(F0*F3*8), Q11), FP2FIX(1.0f/(F0*F4*8), Q11), FP2FIX(1.0f/(F0*F5*8), Q11), FP2FIX(1.0f/(F0*F6*8), Q11), FP2FIX(1.0f/(F0*F7*8), Q11),
	FP2FIX(1.0f/(F1*F0*8), Q11), FP2FIX(1.0f/(F1*F1*8), Q11), FP2FIX(1.0f/(F1*F2*8), Q11), FP2FIX(1.0f/(F1*F3*8), Q11), FP2FIX(1.0f/(F1*F4*8), Q11), FP2FIX(1.0f/(F1*F5*8), Q11), FP2FIX(1.0f/(F1*F6*8), Q11), FP2FIX(1.0f/(F1*F7*8), Q11),
	FP2FIX(1.0f/(F2*F0*8), Q11), FP2FIX(1.0f/(F2*F1*8), Q11), FP2FIX(1.0f/(F2*F2*8), Q11), FP2FIX(1.0f/(F2*F3*8), Q11), FP2FIX(1.0f/(F2*F4*8), Q11), FP2FIX(1.0f/(F2*F5*8), Q11), FP2FIX(1.0f/(F2*F6*8), Q11), FP2FIX(1.0f/(F2*F7*8), Q11),
	FP2FIX(1.0f/(F3*F0*8), Q11), FP2FIX(1.0f/(F3*F1*8), Q11), FP2FIX(1.0f/(F3*F2*8), Q11), FP2FIX(1.0f/(F3*F3*8), Q11), FP2FIX(1.0f/(F3*F4*8), Q11), FP2FIX(1.0f/(F3*F5*8), Q11), FP2FIX(1.0f/(F3*F6*8), Q11), FP2FIX(1.0f/(F3*F7*8), Q11),
	FP2FIX(1.0f/(F4*F0*8), Q11), FP2FIX(1.0f/(F4*F1*8), Q11), FP2FIX(1.0f/(F4*F2*8), Q11), FP2FIX(1.0f/(F4*F3*8), Q11), FP2FIX(1.0f/(F4*F4*8), Q11), FP2FIX(1.0f/(F4*F5*8), Q11), FP2FIX(1.0f/(F4*F6*8), Q11), FP2FIX(1.0f/(F4*F7*8), Q11),
	FP2FIX(1.0f/(F5*F0*8), Q11), FP2FIX(1.0f/(F5*F1*8), Q11), FP2FIX(1.0f/(F5*F2*8), Q11), FP2FIX(1.0f/(F5*F3*8), Q11), FP2FIX(1.0f/(F5*F4*8), Q11), FP2FIX(1.0f/(F5*F5*8), Q11), FP2FIX(1.0f/(F5*F6*8), Q11), FP2FIX(1.0f/(F5*F7*8), Q11),
	FP2FIX(1.0f/(F6*F0*8), Q11), FP2FIX(1.0f/(F6*F1*8), Q11), FP2FIX(1.0f/(F6*F2*8), Q11), FP2FIX(1.0f/(F6*F3*8), Q11), FP2FIX(1.0f/(F6*F4*8), Q11), FP2FIX(1.0f/(F6*F5*8), Q11), FP2FIX(1.0f/(F6*F6*8), Q11), FP2FIX(1.0f/(F6*F7*8), Q11),
	FP2FIX(1.0f/(F7*F0*8), Q11), FP2FIX(1.0f/(F7*F1*8), Q11), FP2FIX(1.0f/(F7*F2*8), Q11), FP2FIX(1.0f/(F7*F3*8), Q11), FP2FIX(1.0f/(F7*F4*8), Q11), FP2FIX(1.0f/(F7*F5*8), Q11), FP2FIX(1.0f/(F7*F6*8), Q11), FP2FIX(1.0f/(F7*F7*8), Q11),
	},
	// const unsigned char ZIGZAG_LUT[64] =
	{
     	0,  1,  8, 16,  9,  2,  3, 10,
    	17, 24, 32, 25, 18, 11,  4,  5,
    	12, 19, 26, 33, 40, 48, 41, 34,
    	27, 20, 13,  6,  7, 14, 21, 28,
    	35, 42, 49, 56, 57, 50, 43, 36,
    	29, 22, 15, 23, 30, 37, 44, 51,
    	58, 59, 52, 45, 38, 31, 39, 46,
    	53, 60, 61, 54, 47, 55, 62, 63,
	},
	
#ifdef JPEG_Q_0 // Quality 0
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
    0x20, 0x16, 0x18, 0x1C, 0x18, 0x14, 0x20, 0x1C,
    0x1A, 0x1C, 0x24, 0x22, 0x20, 0x26, 0x30, 0x50,
    0x34, 0x30, 0x2C, 0x2C, 0x30, 0x62, 0x46, 0x4A,
    0x3A, 0x50, 0x74, 0x66, 0x7A, 0x78, 0x72, 0x66,
    0x70, 0x6E, 0x80, 0x90, 0xB8, 0x9C, 0x80, 0x88,
    0xAE, 0x8A, 0x6E, 0x70, 0xA0, 0xDA, 0xA2, 0xAE,
    0xBE, 0xC4, 0xCE, 0xD0, 0xCE, 0x7C, 0x9A, 0xE2,
    0xF2, 0xE0, 0xC8, 0xF0, 0xB8, 0xCA, 0xCE, 0xC6
    },
    // const unsigned char QUANT_TAB_CHROM[] =
    {
   	0x22, 0x24, 0x24, 0x30, 0x2A, 0x30, 0x5E, 0x34, 
    0x34, 0x5E, 0xC6, 0x84, 0x70, 0x84, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 
    0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6
    }, 
	
#else
#ifdef JPEG_Q_10 // Quality 10
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
    0x10, 0x0B, 0x0C, 0x0E, 0x0C, 0x0A, 0x10, 0x0E,
    0x0D, 0x0E, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
    0x1A, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
    0x1D, 0x28, 0x3A, 0x33, 0x3D, 0x3C, 0x39, 0x33,
    0x38, 0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40, 0x44,
    0x57, 0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57,
    0x5F, 0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D, 0x71,
    0x79, 0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63
    },
    // const unsigned char QUANT_TAB_CHROM[] =
    {
	0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2F, 0x1A, 
    0x1A, 0x2F, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
    0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
    }, 
	#else
#ifdef JPEG_Q_20 // Quality 20
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
    0x0C, 0x08, 0x09, 0x0B, 0x09, 0x08, 0x0C, 0x0B,
    0x0A, 0x0B, 0x0E, 0x0D, 0x0C, 0x0F, 0x13, 0x20,
    0x14, 0x13, 0x11, 0x11, 0x13, 0x27, 0x1C, 0x1D,
    0x17, 0x20, 0x2E, 0x28, 0x30, 0x30, 0x2D, 0x28,
    0x2C, 0x2C, 0x33, 0x39, 0x49, 0x3E, 0x33, 0x36,
    0x45, 0x37, 0x2C, 0x2C, 0x40, 0x57, 0x40, 0x45,
    0x4C, 0x4E, 0x52, 0x53, 0x52, 0x31, 0x3D, 0x5A,
    0x60, 0x59, 0x50, 0x60, 0x49, 0x50, 0x52, 0x4F
	},
    // const unsigned char QUANT_TAB_CHROM[] =
    {
    0x0D, 0x0E, 0x0E, 0x13, 0x10, 0x13, 0x25, 0x14, 
    0x14, 0x25, 0x4F, 0x34, 0x2C, 0x34, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 
    0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F
	}, 

#else
#ifdef JPEG_Q_90 // Quality 90
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x04,
		0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x03, 0x03,
		0x02, 0x04, 0x05, 0x05, 0x06, 0x06, 0x05, 0x05,
		0x05, 0x05, 0x06, 0x07, 0x09, 0x07, 0x06, 0x06,
		0x08, 0x06, 0x05, 0x05, 0x08, 0x0A, 0x08, 0x08,
		0x09, 0x09, 0x0A, 0x0A, 0x0A, 0x06, 0x07, 0x0B,
		0x0C, 0x0B, 0x0A, 0x0C, 0x09, 0x0A, 0x0A, 0x09	
	},
    // const unsigned char QUANT_TAB_CHROM[] =
    {
	0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x04, 0x02, 
    0x02, 0x04, 0x09, 0x06, 0x05, 0x06, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 
    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09
    }, 
#else
#ifdef JPEG_Q_95 // Quality 95
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01,
		0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x02, 0x02,
		0x02, 0x02, 0x03, 0x03, 0x04, 0x03, 0x03, 0x03,
		0x04, 0x03, 0x02, 0x02, 0x04, 0x05, 0x04, 0x04,
		0x04, 0x04, 0x05, 0x05, 0x05, 0x03, 0x03, 0x05,
		0x06, 0x05, 0x05, 0x06, 0x04, 0x05, 0x05, 0x04
	},
    // const unsigned char QUANT_TAB_CHROM[] =
    {
	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 
    0x01, 0x02, 0x04, 0x03, 0x02, 0x03, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04

    },
#else
#ifdef JPEG_Q_100 // Quality 100
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
	},
    // const unsigned char QUANT_TAB_CHROM[] =
    {
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 
    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
    },
#else  // Quality 50
    // const unsigned char QUANT_TAB_LUMIN[] = 
	{
		0x08, 0x05, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07,
		0x06, 0x07, 0x09, 0x08, 0x08, 0x09, 0x0C, 0x14,
		0x0D, 0x0C, 0x0B, 0x0B, 0x0C, 0x18, 0x11, 0x12,
		0x0E, 0x14, 0x1D, 0x19, 0x1E, 0x1E, 0x1C, 0x19,
		0x1C, 0x1B, 0x20, 0x24, 0x2E, 0x27, 0x20, 0x22,
		0x2B, 0x22, 0x1B, 0x1C, 0x28, 0x36, 0x28, 0x2B,
		0x2F, 0x31, 0x33, 0x34, 0x33, 0x1F, 0x26, 0x38,
		0x3C, 0x38, 0x32, 0x3C, 0x2E, 0x32, 0x33, 0x31
	},
    // const unsigned char QUANT_TAB_CHROM[] =
    {
    	0x08, 0x09, 0x09, 0x0C, 0x0A, 0x0C, 0x17, 0x0D, 
    	0x0D, 0x17, 0x31, 0x21, 0x1C, 0x21, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 
    	0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31
    },
#endif
#endif
#endif
#endif
#endif
#endif
	
 //const unsigned short int HUFTAB_LUMIN_AC_Code[256]
	{
		0x000a, 0x0000, 0x0001, 0x0004, 0x000b, 0x001a, 0x0078, 0x00f8, 0x03f6, 0xff82, 0xff83, 0, 0, 0, 0, 0,
		0, 0x000c, 0x001b, 0x0079, 0x01f6, 0x07f6, 0xff84, 0xff85, 0xff86, 0xff87, 0xff88,      0, 0, 0, 0, 0,
		0, 0x001c, 0x00f9, 0x03f7, 0x0ff4, 0xff89, 0xff8a, 0xff8b, 0xff8c, 0xff8d, 0xff8e,      0, 0, 0, 0, 0,
		0, 0x003a, 0x01f7, 0x0ff5, 0xff8f, 0xff90, 0xff91, 0xff92, 0xff93, 0xff94, 0xff95,      0, 0, 0, 0, 0,
		0, 0x003b, 0x03f8, 0xff96, 0xff97, 0xff98, 0xff99, 0xff9a, 0xff9b, 0xff9c, 0xff9d,      0, 0, 0, 0, 0,
		0, 0x007a, 0x07f7, 0xff9e, 0xff9f, 0xffa0, 0xffa1, 0xffa2, 0xffa3, 0xffa4, 0xffa5,      0, 0, 0, 0, 0,
		0, 0x007b, 0x0ff6, 0xffa6, 0xffa7, 0xffa8, 0xffa9, 0xffaa, 0xffab, 0xffac, 0xffad,      0, 0, 0, 0, 0,
		0, 0x00fa, 0x0ff7, 0xffae, 0xffaf, 0xffb0, 0xffb1, 0xffb2, 0xffb3, 0xffb4, 0xffb5,      0, 0, 0, 0, 0,
		0, 0x01f8, 0x7fc0, 0xffb6, 0xffb7, 0xffb8, 0xffb9, 0xffba, 0xffbb, 0xffbc, 0xffbd,      0, 0, 0, 0, 0,
		0, 0x01f9, 0xffbe, 0xffbf, 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc4, 0xffc5, 0xffc6,      0, 0, 0, 0, 0,
		0, 0x01fa, 0xffc7, 0xffc8, 0xffc9, 0xffca, 0xffcb, 0xffcc, 0xffcd, 0xffce, 0xffcf,      0, 0, 0, 0, 0,
		0, 0x03f9, 0xffd0, 0xffd1, 0xffd2, 0xffd3, 0xffd4, 0xffd5, 0xffd6, 0xffd7, 0xffd8,      0, 0, 0, 0, 0,
		0, 0x03fa, 0xffd9, 0xffda, 0xffdb, 0xffdc, 0xffdd, 0xffde, 0xffdf, 0xffe0, 0xffe1,      0, 0, 0, 0, 0,
		0, 0x07f8, 0xffe2, 0xffe3, 0xffe4, 0xffe5, 0xffe6, 0xffe7, 0xffe8, 0xffe9, 0xffea,      0, 0, 0, 0, 0,
		0, 0xffeb, 0xffec, 0xffed, 0xffee, 0xffef, 0xfff0, 0xfff1, 0xfff2, 0xfff3, 0xfff4,      0, 0, 0, 0, 0,
		0x07f9, 0xfff5, 0xfff6, 0xfff7, 0xfff8, 0xfff9, 0xfffa, 0xfffb, 0xfffc, 0xfffd, 0xfffe, 0, 0, 0, 0, 0
	},
	//const unsigned char HUFTAB_LUMIN_AC_Size[256];
	{
	  4,  2,  2,  3,  4,  5,  7,  8, 10, 16, 16,  0, 0, 0, 0, 0,
	  0, 4,  5,  7,  9, 11, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 5,  8, 10, 12, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 6,  9,  12, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
	  0, 6, 10, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 7, 11, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 7, 12, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 9, 15, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
	  0, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
	  0, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
	  0, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
	  0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
	  11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0
	},
	// const unsigned short int HUFTAB_CHROM_AC_Code[256]
	{
		#if 0
		0x0000, 0x0001, 0x0004, 0x000a, 0x0018, 0x0019, 0x0038, 0x0078, 0x01f4, 0x03f6, 0x0ff4,0,0,0,0,0, 
    	0,0x000b, 0x0039, 0x00f6, 0x01f5, 0x07f6, 0x0ff5, 0xff88, 0xff89, 0xff8a, 0xff8b,        0,0,0,0,0,     
    	0,0x001a, 0x00f7, 0x03f7, 0x0ff6, 0x7fc2, 0xff8c, 0xff8d, 0xff8e, 0xff8f, 0xff90,        0,0,0,0,0,
    	0,0x001b, 0x00f8, 0x03f8, 0x0ff7, 0xff91, 0xff92, 0xff93, 0xff94, 0xff95, 0xff96,        0,0,0,0,0,
    	0,0x003a, 0x01f6, 0xff97, 0xff98, 0xff99, 0xff9a, 0xff9b, 0xff9c, 0xff9d, 0xff9e,        0,0,0,0,0,
    	0,0x003b, 0x03f9, 0xff9f, 0xffa0, 0xffa1, 0xffa2, 0xffa3, 0xffa4, 0xffa5, 0xffa6,        0,0,0,0,0,
    	0,0x0079, 0x07f7, 0xffa7, 0xffa8, 0xffa9, 0xffaa, 0xffab, 0xffac, 0xffad, 0xffae,        0,0,0,0,0,
    	0,0x007a, 0x07f8, 0xffaf, 0xffb0, 0xffb1, 0xffb2, 0xffb3, 0xffb4, 0xffb5, 0xffb6,        0,0,0,0,0,
    	0,0x00f9, 0xffb7, 0xffb8, 0xffb9, 0xffba, 0xffbb, 0xffbc, 0xffbd, 0xffbe, 0xffbf,        0,0,0,0,0,
    	0,0x01f7, 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc4, 0xffc5, 0xffc6, 0xffc7, 0xffc8,        0,0,0,0,0,
    	0,0x01f8, 0xffc9, 0xffca, 0xffcb, 0xffcc, 0xffcd, 0xffce, 0xffcf, 0xffd0, 0xffd1,        0,0,0,0,0,
    	0,0x01f9, 0xffd2, 0xffd3, 0xffd4, 0xffd5, 0xffd6, 0xffd7, 0xffd8, 0xffd9, 0xffda,        0,0,0,0,0,
    	0,0x01fa, 0xffdb, 0xffdc, 0xffdd, 0xffde, 0xffdf, 0xffe0, 0xffe1, 0xffe2, 0xffe3,        0,0,0,0,0,
    	0,0x07f9, 0xffe4, 0xffe5, 0xffe6, 0xffe7, 0xffe8, 0xffe9, 0xffea, 0xffeb, 0xffec,        0,0,0,0,0,
    	0,0x3fe0, 0xffed, 0xffee, 0xffef, 0xfff0, 0xfff1, 0xfff2, 0xfff3, 0xfff4, 0xfff5,        0,0,0,0,0,
    	0x03fa, 0x7fc3, 0xfff6, 0xfff7, 0xfff8, 0xfff9, 0xfffa, 0xfffb, 0xfffc, 0xfffd, 0xfffe,0,0,0,0,0
    	#else
    	0x000a, 0x0000, 0x0001, 0x0004, 0x000b, 0x001a, 0x0078, 0x00f8, 0x03f6, 0xff82, 0xff83, 0, 0, 0, 0, 0,
		0, 0x000c, 0x001b, 0x0079, 0x01f6, 0x07f6, 0xff84, 0xff85, 0xff86, 0xff87, 0xff88,      0, 0, 0, 0, 0,
		0, 0x001c, 0x00f9, 0x03f7, 0x0ff4, 0xff89, 0xff8a, 0xff8b, 0xff8c, 0xff8d, 0xff8e,      0, 0, 0, 0, 0,
		0, 0x003a, 0x01f7, 0x0ff5, 0xff8f, 0xff90, 0xff91, 0xff92, 0xff93, 0xff94, 0xff95,      0, 0, 0, 0, 0,
		0, 0x003b, 0x03f8, 0xff96, 0xff97, 0xff98, 0xff99, 0xff9a, 0xff9b, 0xff9c, 0xff9d,      0, 0, 0, 0, 0,
		0, 0x007a, 0x07f7, 0xff9e, 0xff9f, 0xffa0, 0xffa1, 0xffa2, 0xffa3, 0xffa4, 0xffa5,      0, 0, 0, 0, 0,
		0, 0x007b, 0x0ff6, 0xffa6, 0xffa7, 0xffa8, 0xffa9, 0xffaa, 0xffab, 0xffac, 0xffad,      0, 0, 0, 0, 0,
		0, 0x00fa, 0x0ff7, 0xffae, 0xffaf, 0xffb0, 0xffb1, 0xffb2, 0xffb3, 0xffb4, 0xffb5,      0, 0, 0, 0, 0,
		0, 0x01f8, 0x7fc0, 0xffb6, 0xffb7, 0xffb8, 0xffb9, 0xffba, 0xffbb, 0xffbc, 0xffbd,      0, 0, 0, 0, 0,
		0, 0x01f9, 0xffbe, 0xffbf, 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc4, 0xffc5, 0xffc6,      0, 0, 0, 0, 0,
		0, 0x01fa, 0xffc7, 0xffc8, 0xffc9, 0xffca, 0xffcb, 0xffcc, 0xffcd, 0xffce, 0xffcf,      0, 0, 0, 0, 0,
		0, 0x03f9, 0xffd0, 0xffd1, 0xffd2, 0xffd3, 0xffd4, 0xffd5, 0xffd6, 0xffd7, 0xffd8,      0, 0, 0, 0, 0,
		0, 0x03fa, 0xffd9, 0xffda, 0xffdb, 0xffdc, 0xffdd, 0xffde, 0xffdf, 0xffe0, 0xffe1,      0, 0, 0, 0, 0,
		0, 0x07f8, 0xffe2, 0xffe3, 0xffe4, 0xffe5, 0xffe6, 0xffe7, 0xffe8, 0xffe9, 0xffea,      0, 0, 0, 0, 0,
		0, 0xffeb, 0xffec, 0xffed, 0xffee, 0xffef, 0xfff0, 0xfff1, 0xfff2, 0xfff3, 0xfff4,      0, 0, 0, 0, 0,
		0x07f9, 0xfff5, 0xfff6, 0xfff7, 0xfff8, 0xfff9, 0xfffa, 0xfffb, 0xfffc, 0xfffd, 0xfffe, 0, 0, 0, 0, 0
		#endif
    },
	// const unsigned char HUFTAB_CHROM_AC_Size[250]
	{
		#if 0
		2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 12,0,0,0,0,0, 
		0, 4, 6, 8, 9,11,12,16,16,16,16,     0,0,0,0,0, 
		0, 5, 8,10,12,15,16,16,16,16,16,     0,0,0,0,0, 
		0, 5, 8,10,12,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 6, 9,16,16,16,16,16,16,16,16,     0,0,0,0,0,
		0, 6,10,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 7,11,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 7,11,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 8,16,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 9,16,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 9,16,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 9,16,16,16,16,16,16,16,16,16,     0,0,0,0,0, 
		0, 9,16,16,16,16,16,16,16,16,16,     0,0,0,0,0,
		0, 11,16,16,16,16,16,16,16,16,16,    0,0,0,0,0,
		0, 14,16,16,16,16,16,16,16,16,16,    0,0,0,0,0,
		10,15,16,16,16,16,16,16,16,16,16,    0,0,0,0,0,
		#else
		4,  2,  2,  3,  4,  5,  7,  8, 10, 16, 16,  0, 0, 0, 0, 0,
		0, 4,  5,  7,  9, 11, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 5,  8, 10, 12, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 6,  9,  12, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
		0, 6, 10, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 7, 11, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 7, 12, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 9, 15, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16,  0,  0, 0, 0, 0,
		0, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
		0, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
		0, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
		0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0,  0, 0, 0, 0,
		11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0,
	  #endif

	},
	// const unsigned short int HUFTAB_LUMIN_DC_Code[11]
	{
		0x0000, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x000e, 0x001e,
		0x003e, 0x007e, 0x00fe, 0x01fe
	},
	// const unsigned char HUFTAB_LUMIN_DC_Size[11]
	{
		2,3,3,3,3,3,4,5,6,7,8,9
	},
	// const unsigned short int HUFTAB_CHROM_DC_Code[11]
	{
		#if 0
		0x0000, 0x0001, 0x0002, 0x0006, 0x000e, 0x001e, 0x003e, 0x007e,
    	0x00fe, 0x01fe, 0x03fe, 0x07fe
    	#else
    	0x0000, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x000e, 0x001e,
		0x003e, 0x007e, 0x00fe, 0x01fe
		#endif
	},
	// const unsigned char HUFTAB_CHROM_DC_Size[11]
	{
		#if 0
		2,2,2,3,4,5,6,7,8,9,10,11
		#else
		2,3,3,3,3,3,4,5,6,7,8,9
		#endif
	},
};
